import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/analysis_controller.dart';

class AnalysisPage extends StatefulWidget {
  const AnalysisPage({super.key});

  @override
  State<AnalysisPage> createState() => _AnalysisPageState();
}

class _AnalysisPageState extends State<AnalysisPage> {
  final AnalysisController controller = Get.put(AnalysisController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('分析页面'),
      ),
      body: Column(
        children: [
          Expanded(
            child: ListView.builder(
              itemCount: controller.results.length,
              itemBuilder: (context, index) {
                final unit = controller.results.keys.elementAt(index);
                return ExpansionTile(
                  title: Text(unit),
                  children: controller.results[unit]!
                      .map((word) => ListTile(
                            title: Text(word),
                          ))
                      .toList(),
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}

final AnalysisController controller = Get.put(AnalysisController());

@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: const Text('分析页面'),
    ),
    body: Column(
      children: [
        Expanded(
          child: ListView.builder(
            itemCount: controller.results.length,
            itemBuilder: (context, index) {
              final unit = controller.results.keys.elementAt(index);
              return ExpansionTile(
                title: Text(unit),
                children: controller.results[unit]!
                    .map((word) => ListTile(
                          title: Text(word),
                        ))
                    .toList(),
              );
            },
          ),
        ),
      ],
    ),
  );
}
